package com.itc.api.controller;

import cn.hutool.core.util.ObjectUtil;
import com.itc.api.response.Result;
import com.itc.api.response.exception.ResultStatus;
import com.itc.api.service.UserService;
import com.itc.api.utils.RedisUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 用户控制器
 *
 * @author Navcoo
 * @date 2024-11-22
 */
@RestController
@Slf4j
@RequestMapping("/v1/user")
public class UserController {

    @Resource
    private UserService userService;

    @Resource
    private RedisUtils redisUtils;

    /**
     * 登录
     *
     * @param account  账户
     * @param password 密码
     * @return {@link Result }<{@link String }>
     */
    @PostMapping("/login")
    public Result<String> login(
            @RequestParam("account") String account,
            @RequestParam("password") String password
    ) {
        return userService.login(account,password);
    }

    /**
     * 验证
     *
     * @param token 令牌
     * @return {@link Result }<{@link String }>
     */
    @PostMapping("/verify")
    public Result<String> verify(@RequestHeader("token") String token) {
        return userService.verify(token);
    }

    /**
     * 注册
     *
     * @param authCodeToken 验证码令牌
     * @param email         电子邮件
     * @param account       账户
     * @param password      密码
     * @param authCode      身份验证代码
     * @return {@link Result }<{@link String }>
     */
    @PostMapping("/register")
    public Result<String> register(
            @RequestHeader("auth_code_token") String authCodeToken,
            @RequestParam("email") String email,
            @RequestParam("account") String account,
            @RequestParam("password") String password,
            @RequestParam("authCode") String authCode
    ) {
        return userService.register(email, account, password, authCode, authCodeToken);
    }

}